UnityLockstep
![Discord](https://camo.githubusercontent.com/11efd3f3158fd1ccb18752df4c9085faf38304d84c90eebc3f2b0799d61838f6/68747470733a2f2f696d672e736869656c64732e696f2f646973636f72642f3431333135363039383939333032393132302e737667)
Currently the rollback of adding and changing entities should be stable. If you spawn or navigate entities in multiple game-instances, all simulations will end up in a synced state, no matter how many packets drop or how high the lag is. Clientside prediction makes sure that local commands are executed under any condition.
![Video](https://camo.githubusercontent.com/ed959d54ffd4112f4dc35c84e0131697abac802e42f1ff15649764073b127a2b/687474703a2f2f696d672e796f75747562652e636f6d2f76692f66447253547a4d6a7862512f302e6a7067)
Architecture
![Overview Overview](/proepkes/UnityLockstep/raw/master/Docs/Overview.svg)
Server UI
![ServerUI](https://camo.githubusercontent.com/063f71dfb208a4dc7630e31056f7772963d4f7abb07becdf9c4e2c695adfead6/68747470733a2f2f692e696d6775722e636f6d2f623744374a32582e706e67)
Getting started
Open Server.LiteNetLib/Server.LiteNetLib.sln
Run Server-project (Console), enter "1" when asked for room-size
Open SampleScene in Unity
Hit play and wait until connection to server is established
Holding right mouse button will continously spawn new agents, press 'X' to navigate all agents to your current mouse position
Getting started (multiplayer)
Build and run the Unityproject
Start the server. The roomsize will default to 2 after a few seconds of no input
Hit play in Unity so you should now have two instances of the game running
Wait until both players are connected to the server. The server will display a message when the simulation has started.
For controls, same as above
Work in progress (ordered by priority)
Synchronizing framerate. If a client lags too much or lag compensation is too low, the delayed input will force every other client to constantly rollback the simulation. The project requires a solution to minimize the need of rollback for every client.
Performance spikes are currently by design. In case of an input from the very past, a rollback of many (speak: thousands of) ticks at once occur. Adding constraints like max. input-offset and adjusting framerates for slow clients will help improving everyones performance. The target-frame for rollback is also not optimized, this can save lots of performance too.
Rollback for despawned (e.g. killed) entities is not implemented yet, it will arrive after navigation, combat/projectiles and health is working.
Dependencies
The ECS-Project currently targets .NET Framework 4.6.1 (#806)
The server targets .NET Core Framework 2.2.103 (link to setup)
References
Inspired by LockstepFramework, in memory of SnpM:
https://github.com/SnpM/LockstepFramework
Uses a fork of BEPUPhysics for deterministic physics:
https://github.com/sam-vdp/bepuphysics1int
Uses FixedMath.Net for deterministic fp-calculations:
https://github.com/asik/FixedMath.Net
Uses Entitas as ECS Framework:
https://github.com/sschmid/Entitas-CSharp
The project includes an implementation example using LiteNetLib:
https://github.com/RevenantX/LiteNetLib
Initial commit was targeting the following protocol: https://www.reddit.com/r/Unity3D/comments/aewepu/rts_networking_simulate_on_serverbeat/. The project has shifted to an architecture you see above.
Limitations
Physics values are limited to 1000 so keep your world in these limitations or shift the world when your values become too large
|